<?php
include("check.php");
/*include("check2.php");*/
include_once("../function.php");
include_once("../class/system_class.php");
include_once("../class/ulevel_class.php");
include_once ("../bonus.php");

header("Content-Type: text/html;charset=utf-8");
session_start();

$system=new system_class();
$ulevel=new ulevel_class();
$_sys=$system->system_information(1);

$us=que_select_cl('member',$_SESSION['ID']);
$_iul=$ulevel->getulevelbyulevel($us['ulevel']);
if ($_POST['submit']){
	$uid=$_SESSION['ID'];
	$jine=$_POST['jine'];
	if ($jine>0){
		$ze=0;
		if ($_POST['lx']==0 ){
			$ze=$us['mey'];
		}elseif ($_POST['lx']==1){
			$ze=$us['zsq'];	
		}elseif ($_POST['lx']==3){
			$ze=$us['gwb'];	
		}elseif($_POST['lx']==4){
		    $ze=$us['cfxf'];
        }
		if ($ze>=$jine){
			$zhuanhuan['uid']=$uid;
			$zhuanhuan['nickname']=$_SESSION['nickname'];
			$zhuanhuan['username']=$us['username'];
			$zhuanhuan['jine']=$jine;
			$zhuanhuan['zdate']=now();
			$zhuanhuan['lx']=$_POST['lx'];
			add_insert_cl('zhuanhuan',$zhuanhuan);
			if ($_POST['lx']==0){
				$us_update['mey']=$us['mey']-$jine;
				$us_update['zsq']=$us['zsq']+$jine;
				//tongbujine($jine,$us['usertel'],2);
			}elseif($_POST['lx']==1){
				$us_update['zsq']=$us['zsq']-$jine;
				$us_update['mey']=$us['mey']+$jine;
			}elseif($_POST['lx']==2){
				$us_update['zsq']=$us['zsq']-$jine;
				$us_update['gwb']=$us['gwb']+$jine;
			}elseif($_POST['lx']==3){
				$us_update['gwb']=$us['gwb']-$jine;
				$us_update['zsq']=$us['zsq']+$jine;
			}elseif($_POST['lx']==4){
			    if($_iul['yl10']<$us['pv']+$jine/2){
                    $cha=$_iul['yl10']-$us['pv'];
                    if($cha<$jine/2){
                        $us_update['cfxf']=$us['cfxf']-$jine;
                        $us_update['pv']=$us['pv']+$cha;
                    }
			    }else{
                    $us_update['cfxf']=$us['cfxf']-$jine;
                    $us_update['pv']=$us['pv']+$jine/2;
                }
            }
			edit_update_cl('member',$us_update,$us['id']);
	/*		isdd();
            if($_sys['chaifen']==1){
                $sql="select sum(pv) as pv from member where 1=1";
                $pv=getOne($sql);
                if ($_sys['danjia']>=4){
                    $sql="select * from member where ispay=1";
                    $re=mysql_query($sql);
                    $_bonus_cl=new bonus_class();
                    while($rs=mysql_fetch_assoc($re)){
                        $_iul=$ulevel->getulevelbyulevel($rs['ulevel']);
                        $mepv=$rs['pv']*2;
                        if($_iul['yl10']<$mepv){
                            $cha=$_iul['yl10']-$rs['pv'];
                            if($cha<$mepv){
                                $member_update['pv']=$rs['pv']+$cha;
                            }
                        }else{
                            $member_update['pv']=$rs['pv']*2;
                        }
                        edit_update_cl("member",$member_update,$rs['id']);
                    }
                    edit_sql("update systemparameters set danjia=2 where id=1");
                }*/
			echo "<script language=javascript>alert('货币转换成功.\\n本次转换金额:".$jine."');window.location.href='?'</script>";
		}else{
			echo "<script language=javascript>alert('您的余额不足,无法转换.');window.location.href='?'</script>";	
		}
	}else{
		echo "<script language=javascript>alert('转换金额不正确,请确认后重新转换');window.location.href='?'</script>";	
	}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
<title>货币转换</title>
<script language="javascript">
<!--
function select() {
    lx=document.form1.lx.value;
    if(lx=="0"){
        document.getElementById('a1').style.display="";
        document.getElementById('a2').style.display="";
        document.getElementById('z1').style.display="none";
        document.getElementById('z2').style.display="none";
    }else if(lx=="4"){
        document.getElementById('a1').style.display="none";
        document.getElementById('a2').style.display="none";
        document.getElementById('z1').style.display="";
        document.getElementById('z2').style.display="";
    }
}
function CheckForm(){
	jine=document.form1.jine.value;
	if(jine.length == 0){
		alert("温馨提示:\n请输入转换金额.");
		document.form1.jine.focus();
		return false;
	}
	if(jine <= 0){
		alert("温馨提示:\n转换金额必须大于0.");
		document.form1.jine.focus();
		return false;
	}

    	if(jine % <?=$_sys['fanli']?> != 0){
		alert("温馨提示:\n转换金额必须为<?=$_sys['fanli']?>的倍数.");
		document.form1.jine.focus();
		return false;
	}
	return true;
}
-->
</script>
</head>
<body>
<?php
$title="货币转换";
include_once("./public/header_nav.html");
?>
<form name="form1" method="post" action="?" onSubmit="return CheckForm();">
<table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
	<tr id="a1">
    <td width="46%" height="22" align="right">奖金币余额：</td>
    <td width="54%" align="left"><?=$us['mey']?></td>
  </tr>
<!--  <tr>
    <td width="46%" height="22" align="right">电子币余额：</td>
    <td width="54%" align="left"><?/*=$us['gwb']*/?></td>
  </tr>-->
  <tr id="a2">
    <td width="46%" height="22" align="right">报单币余额：</td>
    <td width="54%" align="left"><?=$us['zsq']?></td>
  </tr>
   <tr id="z1" style="display: none">
    <td width="46%" height="22" align="right">专用币余额：</td>
    <td width="54%" align="left"><?=$us['cfxf']?></td>
  </tr>
    <tr id="z2" style="display: none">
    <td width="46%" height="22" align="right">积分余额：</td>
    <td width="54%" align="left"><?=$us['pv']?></td>
  </tr>
  <tr>
    <td width="46%" height="22" align="right">转换类型：</td>
    <td width="54%" align="left">
      <select name="lx" id="lx" onchange="select()" >
          <?php if($zhison1==1){?>
              <option value="0"><?=$zhuanghuanlx1?></option>
          <?php }?>
          <?php if($zhison2==1){?>
              <option value="1"><?=$zhuanghuanlx2?></option>
          <?php }?>
<!--        <option value="1">报单币转奖金币</option>-->
   <!-- <option value="1">奖金转购物币</option>-->
   <!--     <option value="2">报单币转电子币</option>-->


      </select></td>
  </tr>
  <tr>
    <td height="22" align="right">转换金额：</td>
    <td align="left"><input name="jine" type="text" id="jine" size="10" maxlength="10"></td>
  </tr>
</table>
<table align="center" width="100%">
        <tr align="center">
          <td><input name="submit" id="submit" type="submit" class="button_green" value="转  换"></td>
        </tr>
  </table>
<br>
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
        <td height="20" colspan="5" align="center"> 转 换 记 录</td>
      </tr>
      <tr>
        <td align="center">会员编号</td>
        <td align="center">会员姓名</td>
        <td align="center">转换金额</td>
        <td align="center">转换类型</td>
        <td align="center">转换时间</td>
        
    </tr>
      <?php
	  	$pagesize = 10; //设置每页记录数 
	  	$sql = "SELECT * FROM `zhuanhuan` WHERE uid=".$_SESSION['ID']."";
		if($query = mysql_query($sql)){
	  		$sum = mysql_num_rows($query); //计算总记录数 
		}else{
			$sum=0;	
		} 
		if($sum % $pagesize == 0) //计算总页数 
			$total = (int)($sum/$pagesize); 
		else 
			$total = (int)($sum/$pagesize) + 1; 
			if (isset($_GET['page'])) //获得页码 
			{ 
				$p = (int)$_GET['page'];
			} 
			else 
			{ 
				$p = 1;
			}
			if ($p>$total){
				$p=$total;	
			}
		$start = $pagesize * ($p - 1); //计算起始记录 
      	$sql = "SELECT * FROM `zhuanhuan` WHERE uid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
		if($query = mysql_query($sql)){
		while ($row=mysql_fetch_array($query)){
	  ?>
      <tr>
        <td align="center"><?=$row['nickname']?></td>
        <td align="center"><?=$row['username']?></td>
        <td align="center"><?=$row['jine']?></td>
          <td align="center"><?php if ($row['lx']==0){ echo $zhuanghuanlx1; }elseif($row['lx']==1){ echo $zhuanghuanlx2; }elseif($row['lx']==2){ echo $zhuanghuanlx3; }elseif($row['lx']==3){?>电子币转充值积分<?php }elseif($row['lx']==4){?>专用币转积分<?php }?></td>
          <td align="center"><?=$row['zdate']?></td>
		
      </tr>
      <?php
			}
		}
	  ?>
  </table>
  <table width="100%" border="0" class="ziti">
          <tr>
            <td align="left">&nbsp;</td>
            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
          </tr>
        </table>
</form>
<?php include_once ("public/footer_nav.html")?>
</body>
</html>